import { createRouter, createWebHashHistory } from 'vue-router'
import layout from '@/views/layout/index'
import UserManageRouter from './modules/UserManage'
import RoleListRouter from './modules/RoleList'
import PermissionListRouter from './modules/PermissionList'
import ArticleRouter from './modules/Article'
import ArticleCreaterRouter from './modules/ArticleCreate'
import store from '@/store'
// 私有路由表
export const provideRouter = [
  UserManageRouter,
  RoleListRouter,
  PermissionListRouter,
  ArticleRouter,
  ArticleCreaterRouter
]
// 公开路由表
export const publicRoter = [
  {
    path: '/login',
    component: () => import('@/views/login/index')
  },
  {
    path: '/',
    component: layout,
    redirect: '/profile',
    children: [
      {
        path: '/profile',
        component: () => import('@/views/profile/index'),
        meta: {
          title: 'profile',
          icon: 'el-icon-user'
        }
      },
      {
        path: '/404',
        name: 401,
        component: () => import('@/views/error-page/404')
      },
      {
        path: '/401',
        name: 404,
        component: () => import('@/views/error-page/401')
      }
    ]
  }
]
export const removeRouter = () => {
  if (
    store.getters.userInfo &&
    store.getters.userInfo.permission &&
    store.getters.userInfo.permission.menus
  ) {
    store.getters.userInfo.permission.menus.forEach((item) => {
      router.removeRoute(item)
    })
  }
}
const router = createRouter({
  history: createWebHashHistory(),
  routes: publicRoter
})

export default router
